﻿using System;
using ComputationalCore.Helper;

namespace BehaviorModel.Block.RandomGenerator
{
    /// <summary>
    /// Random generator with Poisson strategy.
    /// </summary>
    public class PoissonRandomGenerator : IRandomGenerator
    {
        public double Lambda { get; set; }

        public PoissonRandomGenerator()
        {
            Lambda = 1;
        }

        public PoissonRandomGenerator(double lambda)
        {
            Lambda = lambda;
        }

        #region Get Next

        public double GetNext(double prev)
        {
            return GetNext() + prev;
        }

        public double GetNext()
        {
            var next = -1/Lambda*Math.Log(RandomHelper.NextDouble());

            return next;
        }

        #endregion
    }
}
